# 解除运行限制
# Set-ExecutionPolicy Bypass -Scope Process
#
#
# 设置你想删除的网关地址
$TargetGateway = "10.129.188.14"

# 获取所有以指定网关为下一跳的路由
$RoutesToRemove = Get-NetRoute | Where-Object { $_.NextHop -eq $TargetGateway }

# 遍历这些路由并删除它们
foreach ($Route in $RoutesToRemove) {
    Write-Host "Deleting route: $($Route.DestinationPrefix) via $($Route.NextHop)"
    # 注意：在实际执行删除操作前，确保已经进行了充分的验证，以防误删重要路由
    # 若要执行删除，请取消下一行的注释
    Remove-NetRoute -DestinationPrefix $Route.DestinationPrefix -NextHop $Route.NextHop -Confirm:$false
}

Write-Host "Done. Routes matching gateway $TargetGateway would have been deleted."

# 添加目标ip的路由
route add 172.30.1.110 mask 255.255.255.255 10.129.188.14 if 10.129.188.17

Get-NetRoute